<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>智能超市</title>
    <link href="../bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../style.css"/>
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="container cont-voice">
    <div class="row">
        <input id="str" type="text" class="form-control" placeholder="请输入"/>
    </div>
    <div class="row" style="margin-top: 30px; text-align: center;">
        <a class="btn btn-lg btn-info" id="play" href="##">朗读</a>
    </div>
</div>
<audio src="##" id="audio"></audio>
<script src="../jquery.min.js"></script>
<script src="../bootstrap.min.js"></script>
<script>
    var url = 'http://andyhtree.com/googleNiangProxy.php?str=';
    var lock = false;
    function handler(){
        lock = true;
        var $self = $('#play');
        var val = $('#str').val();
        $('#str').val('');
        $self.addClass('disabled');
        $('#audio').attr('src', url + val).on('ended', function(){
            lock = false;
            $self.removeClass('disabled');
        }).get(0).play();
    }
    $('#play').click(handler);
    $('#str').on('change', handler);
</script>
</body>
</html>